package com.yulongtian.oneProblemEveryDay.month202301;

import java.util.HashMap;
import java.util.List;

/**
 * @author yulongTian
 * @create 2023-01-12 20:14
 */
public class Test10 {
    public static void main(String[] args) {

    }

    public static String evaluate(String s, List<List<String>> knowledge) {
        HashMap<String, String> map = new HashMap<>();
        for (List<String> strings : knowledge) {
            map.put(strings.get(0), strings.get(1));
        }

        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '(') {
                i++;
                StringBuilder temp = new StringBuilder();
                while (s.charAt(i) != ')') {
                    temp.append(s.charAt(i));
                    i++;
                }
                if(!map.isEmpty()&&map.containsKey(temp.toString())){
                    ans.append(map.get(temp.toString()));
                }else{
                    ans.append("?");
                }
            } else {
                ans.append(s.charAt(i));
            }
        }

        return ans.toString();
    }
}
